myApp.api = {
    // host: 'http://localhost:3000',
    host: 'http://fin.rean.ren',
    ajax: function (options, success) {
        let settings = {
            url: myApp.api.host + options.url,
            method: options.method || 'GET',
            contentType: 'application/json',
            dataType: 'json',
            success: success,
            error: function (XHR, textStatus) {
                myApp.alert('无法连接服务，请稍后再试', '网络异常');
            }
        };
        settings.data = JSON.stringify(options.data);
        return $$.ajax(settings);
    },
    createFinance: function (settings) {
        myApp.api.ajax({url: '/finance', method: 'POST', data: settings.data}, function (data) {
            settings.success(data);
        });
    },
    deleteFinance: function (settings) {
        myApp.api.ajax({'url': '/finance/delete', method: 'POST', data: settings.data}, (data) => {
            settings.success(data)
        })
    },
    getToday: function (settings) {
        myApp.api.ajax({url: '/finance/today', data: settings.data}, function (data) {
            settings.success(data);
        });
    },
    getMonth: (settings) => {
        myApp.api.ajax({url: '/finance/month'}, (data) => {
            settings.success(data);
        })
    },
    getYear: (settings) => {
        myApp.api.ajax({url: '/finance/year', method: 'POST', data: settings.data}, (data) => {
            settings.success(data);
        })
    },
    getAll: (settings) => {
        myApp.api.ajax({url: '/finance/all'}, (data) => {
            settings.success(data);
        })
    }
};

